using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HourglassSystem
{
    public class TimeLineManager : MonoBehaviour
    {
        public Camera _TLCamera;
        private TimeLineReactant[] _reactantPool;
        private bool _isOnLine;
        private int _timeLineCode;

        private void Awake()
        {
            _reactantPool = gameObject.GetComponentsInChildren<TimeLineReactant>();
        }

        public void INI_TimeLine(int timeLineCode)
        {
            _timeLineCode = timeLineCode;
            _TLCamera.gameObject.SetActive(false);
            for (int i = 0; i < _reactantPool.Length; i++)
            {
                _reactantPool[i].INI_TLReactant(timeLineCode);
            }
            _isOnLine = false;
        }

        public void SwitchIn()
        {
            if (!_isOnLine)
            {
                _TLCamera.gameObject.SetActive(true);
                for (int i = 0; i < _reactantPool.Length; i++)
                {
                    _reactantPool[i].TimeLineSwitchIn();
                }
                _isOnLine = true;
            }
        }

        public void SwitchOut()
        {
            if (_isOnLine)
            {
                _TLCamera.gameObject.SetActive(false);
                for (int i = 0; i < _reactantPool.Length; i++)
                {
                    _reactantPool[i].TimeLineSwitchOut();
                }
                _isOnLine = false;
            }
        }
    }
}